package code.reptile.main;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import code.excel.poi.WriteToFile;
import code.reptile.core.AnalzeHtml;
import code.reptile.core.DownLoadFile;

/**
* <p></p>
*
* @version 1.0
* @author:huangwf
* @date:2017/8/18 11:42
* @history
*/

public class Yincai {

private final static String EXCELPATH = "reptile/out/excel/info.xls";
private final static String HTMLPATH = "reptile\\out\\html\\yingcai/";

public static void main(String[] args) throws IOException, InvalidFormatException {
String url = "http://www.chinahr.com/dongguan/jobs/";
String path;
path = DownLoadFile.downloadFile(url, HTMLPATH);
//        path = "excel/out/html/yingca/www.chinahr.com_sou_.html";
Document document = AnalzeHtml.analzeHtml(path);
Elements links = AnalzeHtml.analzeHtmlByClass(document, "all-job");
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for (Element link : links) {
Elements spans = link.getElementsByTag("a");
for (Element span : spans) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(AnalzeHtml.HTML_TEXT, span.attr("href"));
map.put(AnalzeHtml.HTML_ATTR, span.text());
list.add(map);
}
}
WriteToFile.wirteToExcel(EXCELPATH, list, "职位编号");
}
}
